<?php
/**
 * Created by PhpStorm.
 * User: PHP
 * Date: 2021/6/8
 * Time: 14:11
 */

namespace App\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;

class VersionRequest extends FormRequest
{

    public function authorize()
    {
        return true;
    }


    //验证规则
    protected $rules = [
        'title' => 'required|between:3,20',
        'content'=>'required',
        'version'=>'required',
        'type'=>'required',

    ];


    public function messages() {
        return  [

            'title.required'=>'版本标题必须填写.',
            'title.between'=>'版本标题必须在3到20位之间',
            'content.required'=>'版本内容必须填写',
            'version.required'=>'版本号必须填写',
            'id.required' => '版本Id必须传递',
            'type.required' => '版本所属类型必须传递',
        ];

    }


    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = $this->rules;

        if (Request::getPathInfo() == '/adminapi/version/add')//如果是login方法
        {
            $rules['title'] = 'required';
            $rules['content'] = 'required';
            $rules['version'] = 'required';
            $rules['type'] = 'required';
        }

        if (Request::getPathInfo() == '/adminapi/version/update')//如果是login方法
        {
            $rules['id'] = 'required';
            $rules['content'] = 'required';
        }

        if (Request::getPathInfo() == '/adminapi/version/info')//如果是login方法
        {
            $rules['id'] = 'required';
        }



        return $rules;

    }










}
